package constant.milk.cashbook.insert;

import constant.milk.cashbook.R;
import constant.milk.cashbook.SuperActivity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;

public class MoveAssetChoiceActivity extends SuperActivity
{
	public static final int OUT_FLAG = 0;
	public static final int IN_FLAG = 1;
	
	public static final String TYPE_DATA = "TYPE_DATA";
	public static final String MOVE_TYPE = "MOVE_TYPE";
	
	private View realView;
	private View bankView;
	private View checkView;
	private View creditView;
	
	private RadioButton realRadio;
	private RadioButton bankRadio;
	private RadioButton checkRadio;
	private RadioButton creditRadio;
	
	private Button checkButton;
	
	private String typeStr;
	
	private int flag;
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.move_asset_choice_activity);
		
		setTitle("타입선택");
		
		setGoneTipButton();
		
		setFindViewId();
		setOnClick();
		setData();
	}

	@Override
	protected void setFindViewId()
	{
		realView = findViewById(R.id.typeRealView);
		bankView = findViewById(R.id.typeBankView);
		checkView = findViewById(R.id.typeCheckView);
		creditView = findViewById(R.id.typeCreditView);
		
		realRadio = (RadioButton) findViewById(R.id.typeRealRadio);
		bankRadio = (RadioButton) findViewById(R.id.typeBankRadio);
		checkRadio = (RadioButton) findViewById(R.id.typeCheckRadio);
		creditRadio = (RadioButton) findViewById(R.id.typeCreditRadio);
		
		checkButton = (Button) findViewById(R.id.checkButton);
	}

	@Override
	protected void setOnClick()
	{
		realView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				setRealRadio();
			}
		});
		
		bankView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				setBankRadio();
			}
		});
		
		checkView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				setCheckRadio();
			}
		});
		
		creditView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				setCreditRadio();
			}
		});
		
		checkButton.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				Intent intent = new Intent();
				intent.putExtra(TYPE_DATA, typeStr);
				setResult(Activity.RESULT_OK, intent);
				finish();
			}
		});
	}
	
	@Override
	protected void setData()
	{
		Intent intent = getIntent();
		
		String typeString = intent.getStringExtra(TYPE_DATA);
		flag = intent.getIntExtra(MOVE_TYPE, 0);
		
		if (getResources().getString(R.string.realAsset).equals(typeString))
		{
			setRealRadio();
		}
		else if (getResources().getString(R.string.bankAsset).equals(typeString))
		{
			setBankRadio();
		}
		else if (getResources().getString(R.string.checkCardAsset).equals(typeString))
		{
			setCheckRadio();
		}
		else if (getResources().getString(R.string.creditCardAsset).equals(typeString))
		{
			setCreditRadio();
		}
		
		if (flag == IN_FLAG)
		{
			creditView.setVisibility(View.GONE);
		}
	}
	
	private void setRealRadio()
	{
		realRadio.setChecked(true);
		bankRadio.setChecked(false);
		checkRadio.setChecked(false);
		creditRadio.setChecked(false);
		typeStr = getResources().getString(R.string.realAsset);
	}
	
	private void setBankRadio()
	{
		realRadio.setChecked(false);
		bankRadio.setChecked(true);
		checkRadio.setChecked(false);
		creditRadio.setChecked(false);
		typeStr = getResources().getString(R.string.bankAsset);
	}
	
	private void setCheckRadio()
	{
		realRadio.setChecked(false);
		bankRadio.setChecked(false);
		checkRadio.setChecked(true);
		creditRadio.setChecked(false);
		typeStr = getResources().getString(R.string.checkCardAsset);
	}
	
	private void setCreditRadio()
	{
		realRadio.setChecked(false);
		bankRadio.setChecked(false);
		checkRadio.setChecked(false);
		creditRadio.setChecked(true);
		typeStr = getResources().getString(R.string.creditCardAsset);
	}

	@Override
	protected void tipButton()
	{
	}

}
